using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace MVCFramework.Presenter.Commands
{
    public class ChangeValueCommand : Command 
    {
        PropertyDescriptor PropDescr;
        object RefObject;
        object OldValue;
        object NewValue;

        public ChangeValueCommand(PropertyDescriptor pd, object refObject, object oldValue, object newValue)
        {
            PropDescr = pd;
            RefObject = refObject;
            OldValue = oldValue;
            NewValue = newValue;
        }

        override public bool Execute()
        {
            PropDescr.SetValue(RefObject, NewValue);
            return true;
        }
        override public bool UnExecute()
        {
            PropDescr.SetValue(RefObject, OldValue);
            return true;
        }

        public override CommandApplicator Applicator
        {
            get
            {
                return delegate(object _object)
                {
                    return new ChangeValueCommand(PropDescr, _object, OldValue, NewValue);
                };
            }
        }
        public override string Description
        {
            get
            {
               return "Property of " + RefObject +  " was Modified "  ;
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }
    }
}
